package work.shyk.cdp.nexus;

import com.sun.jersey.api.client.WebResource;
import org.sonatype.nexus.client.core.NexusClient;
import org.sonatype.nexus.client.core.NexusStatus;
import org.sonatype.nexus.client.core.subsystem.repository.RepositoryStatus;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyGroupRepository;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyGroupRepositoryFactory;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyHostedRepository;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyHostedRepositoryFactory;
import org.sonatype.nexus.client.rest.AuthenticationInfo;
import org.sonatype.nexus.client.rest.BaseUrl;
import org.sonatype.nexus.client.rest.Protocol;
import org.sonatype.nexus.client.rest.UsernamePasswordAuthenticationInfo;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClientFactory;
import org.sonatype.nexus.client.rest.jersey.NexusClientFactoryImpl;
import org.sonatype.nexus.rest.model.RepositoryBaseResource;
import org.sonatype.nexus.rest.model.RepositoryListResourceResponse;
import org.sonatype.nexus.rest.model.RepositoryResourceResponse;
import work.shyk.cdp.xmlDemo.XMLUtil;

import java.util.List;

/**
 * description: <br>
 * createTime: 2020/10/2017:03 <br>
 *
 * @author zzh
 */
public class Main {

    public static void main(String[] args) {
        JerseyNexusClientFactory factory = new JerseyNexusClientFactory();
        BaseUrl nexus = new BaseUrl(Protocol.HTTP, "10.238.222.166", 8081, "/nexus");
        AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo("admin", "Admin123!");
        JerseyNexusClient client = (JerseyNexusClient) factory.createFor(nexus, authenticationInfo);
        JerseyGroupRepositoryFactory jerseyGroupRepositoryFactory = new JerseyGroupRepositoryFactory();
        JerseyGroupRepository jerseyGroupRepository = jerseyGroupRepositoryFactory.create(client, "public");
        RepositoryStatus s = jerseyGroupRepository.status();
        System.out.println(s.isInService());

//        JerseyHostedRepositoryFactory jerseyHostedRepositoryFactory = new JerseyHostedRepositoryFactory();
//        JerseyHostedRepository jerseyHostedRepository = jerseyHostedRepositoryFactory.create(client, "test");
//        jerseyHostedRepository.remove();
        JerseyHostedRepository jerseyHostedRepository = new JerseyHostedRepository(client, "test");
        jerseyHostedRepository.save();

//        RepositoryResourceResponse repositoryResourceResponse = new RepositoryResourceResponse();
//        RepositoryBaseResource repositoryBaseResource = new RepositoryBaseResource();
//        repositoryResourceResponse.setData(repositoryBaseResource);
//        repositoryBaseResource.setId("test");
//        repositoryBaseResource.setName("test");
//        repositoryBaseResource.setRepoType("hosted");
//        repositoryBaseResource.setFormat("maven2");
//        repositoryBaseResource.setProvider("maven2");
//        repositoryBaseResource.setProviderRole("org.sonatype.nexus.proxy.repository.Repository");
//        repositoryBaseResource.setContentResourceURI("http://10.238.222.166:8081/nexus/service/local/repositories/test");
//        repositoryBaseResource.setExposed(true);
//        WebResource.Builder builder = client.serviceResource("repositories");
//        builder.post(XMLUtil.convertToXml(repositoryResourceResponse));

//        builder = client.serviceResource("repositories");
//        RepositoryListResourceResponse repositoryListResourceResponse = builder.get(RepositoryListResourceResponse.class);
//        System.out.println(repositoryListResourceResponse);
        System.out.println("over");
    }
}
